package com.chookss.home.gallery.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.entity.GallerySearchEntity;
import com.chookss.home.gallery.GallerySearchPicListActivity;
import com.chookss.tools.GlideUtils;
import com.chookss.tools.Utils;

import java.util.List;

import io.reactivex.annotations.Nullable;

public class GallerySearchTagAdapter extends BaseQuickAdapter<GallerySearchEntity.TagListBean.ListBean, BaseViewHolderEx> {
    private Activity context;
    private String searchKeyWord,title,startTime,endTime,provides,orgCodes,catalogCodes,tagCodes,provinces,citys,fileTypes;
    public GallerySearchTagAdapter(int layoutResId, Activity context, @Nullable List<GallerySearchEntity.TagListBean.ListBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolderEx helper, GallerySearchEntity.TagListBean.ListBean item) {
        ImageView ivBg = helper.getView(R.id.ivBg);
        LinearLayout llBg = helper.getView(R.id.llBg);
        TextView tvTitle = helper.getView(R.id.tvTitle);
        TextView tvMore = helper.getView(R.id.tvMore);
        LinearLayout.LayoutParams params= (LinearLayout.LayoutParams) llBg.getLayoutParams();
        if(helper.getItemPosition()==getData().size()-1){
            params.setMargins(0,0,0,0);
        }else{
            params.setMargins(0,0,0,Utils.dip2px(context,12));
            llBg.setLayoutParams(params);
        }
        GlideUtils.loadCustomRound(context,item.getImagePath(),ivBg,15);
        tvTitle.setText(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color),item.getTagName(),searchKeyWord));
        tvMore.setText(Utils.changeNumber(item.getImageNum())+"");
        tvMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, GallerySearchPicListActivity.class);
                intent.putExtra("searchKeyWord","");
                intent.putExtra("title",item.getTagName());
                intent.putExtra("searchType",1);
                intent.putExtra("startTime",startTime);
                intent.putExtra("endTime",endTime);
                intent.putExtra("provides",provides);
                intent.putExtra("orgCodes",orgCodes);
                intent.putExtra("catalogCodes",catalogCodes);
                intent.putExtra("tagCodes",item.getTagCode());
                intent.putExtra("provinces",provinces);
                intent.putExtra("citys",citys);
                intent.putExtra("fileTypes",fileTypes);
                context.startActivity(intent);
            }
        });
    }
    public  void setSearchData(String searchKeyWord,String title,String startTime,String endTime,String provides,String orgCodes,String catalogCodes,String tagCodes,String provinces,String citys,String fileTypes){
        this.searchKeyWord = searchKeyWord;
        this.title = title;
        this.startTime = startTime;
        this.endTime = endTime;
        this.provides = provides;
        this.orgCodes = orgCodes;
        this.catalogCodes = catalogCodes;
        this.tagCodes = tagCodes;
        this.provinces = provinces;
        this.citys = citys;
        this.fileTypes = fileTypes;
    }
}
